<?php

/**
* Model:  "Pets_model"
*
* This model allows CodeIgniter to interact with the database - more
* specifically, the "pets" table in the database.  This model allows
* the application to show all pets so the user can select one to learn
* more about, delete a pet (if he's been adopted!), and add a new pet
* record to the database.
*
* Functions:  list_pets, get_pet, remove_pet, add_pet
*
* @author     Brandon A Johnson
* @copyright  LIS4368-01: "Web Development with PHP," Spring 2010
* @version    1.0
* @date       April 24, 2010
*
*/

class Pets_model extends Model {

	/**
	* Pets_model() - constructor
	*
	* allows this file to act as a valid CodeIgniter model
	*/
    function Pets_model()
    {
        parent::Model();
		
		$this->load->database();
    }
	
	/**
	* list_pets()
	*
	* pulls all pet records from the database to put in the drop-down list
	*
	* values passed: none
	*/
	function list_pets()
	{
		$query = $this->db->get('pets');

		return $query->result();
	}
	
	/**
	* get_pet()
	*
	* pulls one specific pet record and gets all the information on
	* that pet to display
	*
	* values passed: $selection - the name of the pet we are looking for
	*/
	function get_pet($selection)
	{
		$query = $this->db->query('SELECT Name, Species, Breed, Age, Weight, Description, Gender, SpayedNeutered FROM pets WHERE Name="' . $selection . '";');
		
		return $query->result();
	}
	
	/**
	* remove_pet()
	*
	* deletes the selected pet from the database
	*
	* values passed: $selection - the name of the pet we want to remove
	*/
	function remove_pet($selection)
	{
		$this->db->query('DELETE FROM pets WHERE Name="' . $selection . '";');
	}
	
	/**
	* add_pet()
	*
	* adds a new pet record to the database
	*
	* values passed: $name - the pet's name
	*                $species - the pet's species (cat, dog, etc.)
	*                $breed - the pet's breed (golden retriever, tabby, etc.)
	*                $age - how old the pet is
	*                $weight - how much the pet weighs in pounds (lbs)
	*                $description - a quick blurb about the pet
	*                $gender - is the pet male or female?
	*                $spayedneutered - if we're taking it in, it has to be fixed!
	*/
	function add_pet($name, $species, $breed, $age, $weight, $description, $gender, $spayedneutered)
	{
		$this->db->query('INSERT INTO pets (Name, Species, Breed, Age, Weight, Description, Gender, SpayedNeutered) VALUES ("' . $name . '", "' . $species . '", "' . $breed . '", "' . $age . '", "' . $weight . '", "' . $description . '", "' . $gender . '", "' . $spayedneutered . '");');
	}
}

/* EOF */